/**
 * Created by lvlq on 16/4/24.
 */
var Sequelize = require("sequelize");
var sequelize = Util("sequelize");

module.exports = sequelize.define("wx", {
    openid: {
        type: Sequelize.STRING,
        field: "openid",
        allowNull: false,
        defaultValue: "",
        comment: "用户openid"
    },
    nick: {
        type: Sequelize.STRING,
        field: "nick",
        allowNull: false,
        defaultValue: "",
        comment: "昵称",
        set: function (val) {
            var base64 = new Buffer(val).toString("base64");
            this.setDataValue('nick', base64);
        },
        get: function () {
            var val = this.getDataValue('nick');
            return new Buffer(val, 'base64').toString();
        }
    },
    phone: {
        type: Sequelize.STRING,
        field: "phone",
        allowNull: false,
        defaultValue: "",
        comment: "手机号"
    }
}, {
    comment: "微信用户表",
    scopes: {
        info: function (openid) {
            return {
                where: {
                    openid: openid
                },
                raw: true
            }
        }
    }
});